﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using Monocle.DataModel;

namespace Monocle.Models
{
    public class HTMLViewModel
    {
        private tHTML _dto;
        public HTMLViewModel(tHTML dto)
        {
            _dto = dto;
        }

        public HTMLViewModel()
        {
            _dto = new tHTML();
        }

        [ScriptIgnore]
        [HiddenInput(DisplayValue = false)]
        public Guid FK_tPage { get; set; }

        [ScriptIgnore]
        [HiddenInput(DisplayValue = false)]
        public Guid FK_tPageItem
        {
            get { return _dto.FK_tPageItem; }
            set { _dto.FK_tPageItem = value; }
        }

        
        [HiddenInput(DisplayValue = false)]
        public Guid ModuleID
        {
            get { return _dto.PK_tHTML; }
            set { _dto.PK_tHTML = value; }
        }

        [ScriptIgnore]
        [HiddenInput(DisplayValue = false)]
        public byte[] Version
        {
            get { return _dto.Version; }
            set { _dto.Version = value; }

        }

        [Display(Name = "Module_HTML_Content", ResourceType = typeof(Resources.Monocle))]
        public String HTMLContent
        {
            get { return _dto.HTML; }
            set { _dto.HTML = value; }
        }

        [ScriptIgnore]
        public String App_URL { get; set; }

        [ScriptIgnore]
        [Display(Name = "PageItemViewModel_Published", ResourceType = typeof(Resources.Monocle))]
        public bool Published { get; set; }

        [Required(ErrorMessageResourceName = "Generic_Required", ErrorMessageResourceType = typeof(Resources.Monocle))]
        [Display(Name = "PageItemViewModel_Name", ResourceType = typeof(Resources.Monocle))]
        public String PageItemName { get; set; }

        /// <summary>
        /// Returns the DTO
        /// </summary>
        /// <returns></returns>
        public tHTML ToDTO()
        {
            return _dto;
        }

        public void UpdateFromDTO(tHTML dto)
        {
            _dto = dto;
        }
    }
}